var my_vue;
$(function() {
	var fromSpace= isEmpty(parseQueryString().fromSpace) ? '0' : parseQueryString().fromSpace;
	var fromGuide= isEmpty(parseQueryString().fromGuide) ? '0' : parseQueryString().fromGuide;
	var code= parseQueryString().itemsId;
	var userType = parseQueryString().userType;
	my_vue = new Vue({
		el: '#vue_info',
		data: {
			type: isEmpty(parseQueryString().type) ? 'dept' : parseQueryString().type,
			dto: {
				userId: '',
				mobile: '',
				name: '测试用户',
				sex: '男',
				nation: '汉',
				birthday: '1991年12月12日',
				address: '苏州市高大上',
				cardNum: '340825190001233434',
				issued: '苏州市公安局',
				life: '2012.03.28-2022.03.28'
			}
		},
		methods: {
			chooseServiceType1: function() {
				window.location = "selfHelpFormInput.html";
			},
			chooseServiceType2: function() {
				window.location = "face2faceWaiting.html";
			},
			exitProcess: function(op) {
				if(op == 'index') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toIndex
					});
				} else if(op == 'scanner') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toScanner
					});
				}
			},
			toIndex: function() {
				window.location = "index.html"
			},
			toScanner: function() {
				window.location = "scannerIndex.html"
			},
			simulateUserDto: function() {
				$.ajax({
					type: "post",
					url: gover.saveUserInfo,
					async: true,
					dataType: 'json',
					data: {
						name: this.dto.name,
						sex: this.dto.sex,
						nation: this.dto.nation,
						birthday: this.dto.birthday,
						address: this.dto.address,
						cardNum: this.dto.cardNum,
						issued: this.dto.issued,
						life: this.dto.life
					},
					success: function(result) {
						if(result.success) {
							console.log(result.data.userId);
							my_vue.dto.userId = result.data.userId;
							my_vue.dto.mobile = result.data.mobile;
							sessionStorage.setItem("dto", toJson(my_vue.dto));
							window.location = "userInfo.html?type="+my_vue.type
							+"&fromSpace="+fromSpace
							+"&fromGuide="+fromGuide
							+"&userType="+userType
							+"&code="+code;

						} else {
							showRedMsg("message", "服务器正忙,请稍候重试");
						}

					},
					error: function(result) {
						showRedMsg("message", "服务器正忙,请稍候重试");
						console.log('保存接口失败:' + toJson(result));
						top.$.closePopWin();
					}
				});
			},
			exitAttendTo: function() {
				$.openDialog({
					'title': '',
					"showClose": false,
					'width': 824,
					'height': 460,
					'url': 'selfHelpExitChoose.html'
				});
			}
		},
		ready: function() {
			//初始化获得总页面数和列表数据
			$("#left").load("../common/gover-left.html");
			getData();
		}
	});
});

//获取身份证信息
function getData() {
	$.ajax({
		url : 'http://192.168.10.144:8700/device/IdCard/read?timeout=60',
		async : true,
		type : 'get',
		dataType : 'json',
		success : function(result) {
			if (result.success == true) {
				if(result.data !=''){
						$(".id-tip").html("身份证信息正在读取中<br/>请等待");
						var keyValue = result.data.rawData.split("|");
							var name = keyValue[0];
							var sex = keyValue[1];
							var cardNum = keyValue[5];
							var address = keyValue[4];
							//身份证正反面照片
							//var imgUp= "http://127.0.0.1:8700"+result.data.frontImage;
							//var imgDown="http://127.0.0.1:8700"+result.data.backImage;
							my_vue.dto.name = keyValue[0];
							my_vue.dto.sex=keyValue[1];
							my_vue.dto.nation=keyValue[2];
							my_vue.dto.birthday=keyValue[3].substring(0,4)+"年"+keyValue[3].substring(4,6)+"月"+keyValue[3].substring(6,8)+"日";
							my_vue.dto.address=keyValue[4];
							my_vue.dto.cardNum=keyValue[5];
							my_vue.dto.issued=keyValue[6];
							my_vue.dto.life=keyValue[7].substring(0,4)+"."+keyValue[7].substring(4,6)+"."+keyValue[7].substring(6,8)
							+"-"+keyValue[8].substring(0,4)+"."+keyValue[8].substring(4,6)+"."+keyValue[8].substring(6,8);
							my_vue.simulateUserDto();
				} else{
					window.setTimeout('getData()', 1000);
				}
			} else {
				showRedMsg('', result.message);
				window.setTimeout('getData()', 1000);
			}
		},
		error : function() {
			var info = '查平飞|男|汉族|19911028|安徽省宿州市埇桥区东关办事处汴河中路７１号|340825199110280454|宿州市公安局埇桥分局|20120328|20220328|';
				var keyValue = info.split("|");
							
							var name = keyValue[0];
							var sex = keyValue[1];
							var cardNum = keyValue[5];
							var address = keyValue[4];
							//身份证正反面照片
							//var imgUp= "http://127.0.0.1:8700"+result.data.frontImage;
							//var imgDown="http://127.0.0.1:8700"+result.data.backImage;
							my_vue.dto.name = keyValue[0];
							my_vue.dto.sex=keyValue[1];
							my_vue.dto.nation=keyValue[2];
							my_vue.dto.birthday=keyValue[3].substring(0,4)+"年"+keyValue[3].substring(4,6)+"月"+keyValue[3].substring(6,8)+"日";
							my_vue.dto.address=keyValue[4];
							my_vue.dto.cardNum=keyValue[5];
							my_vue.dto.issued=keyValue[6];
							my_vue.dto.life=keyValue[7].substring(0,4)+"."+keyValue[7].substring(4,6)+"."+keyValue[7].substring(6,8)
							+"-"+keyValue[8].substring(0,4)+"."+keyValue[8].substring(4,6)+"."+keyValue[8].substring(6,8);
							my_vue.simulateUserDto();
			
			/*
			showRedMsg('','操作失败，请退出后重试');
			return false;*/
		}
	});
}